<template>
  <div class="app-container search-table-box aidex-table">
    <el-card shadow="never" ref="queryRef" style="margin-bottom: 12px;" class="search_card" v-show="showSearch">
      <div class="filter-container">
        <div class="search_box" style="padding-bottom: 16px">
          <el-form :model="queryParams" ref="queryForm" label-width="80px" size="mini">
            <el-row :gutter="10">
              <el-col :md="6" >
                <el-form-item prop="searchValues">
                  <el-select
                    v-model="queryParams.searchValues"
                    multiple
                    filterable
                    remote
                    reserve-keyword
                    clearable
                    placeholder="请输入销方名称/发票代码/发票号码/税款所属期"
                    :remote-method="remoteSearchValue"
                    @change="handleQuery"
                    :loading="remoteSearchValueLoading"
                    style="width: 315px;margin-left: -78px"
                  >
                    <el-option
                      v-for="item in searchValueOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                      :disabled="item.disabled">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :md="2" >
                <el-button size="mini"  @click="toggleAdvanced" type="primary" plain style="padding: 6px 15px;">
                  {{ advanced ? '收起' : '展开' }}
                  <i :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
                </el-button>
              </el-col>
              <el-col :md="16" align="right" class="longBtnBar">
                <el-form-item >
                  <el-button class="filter-item" type="primary" style="margin-left: 8px" :disabled="multiple" @click="handleDeductionApply">勾选抵扣</el-button>
                  <el-button class="filter-item" type="danger" style="margin-left: 8px" :disabled="multiple" @click="handleDeductionApplyCancel">取消抵扣</el-button>
                  <el-button class="filter-item" style="margin-left: 8px" :disabled="multiple" @click="handleDeductionCancelnonApply">勾选不抵扣</el-button>
                  <el-button class="filter-item" type="danger" :disabled="multiple" plain style="margin-left: 8px" @click="handleDeductionCancelnonApplyCancel">取消不抵扣</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <div class="search_advanced_bar" v-if="advanced">
              <el-card shadow="never" >
                <el-row :gutter="16" >
<!--                  <el-col :md="6" >-->
<!--                    <el-form-item label="公司" prop="siteCode">-->
<!--                      <el-input v-model="queryParams.params.companynames" maxlength = 0 clearable placeholder="请选择公司" >-->
<!--                        <el-button slot="append" icon="el-icon-search" @click="openSearchsiteCodeDialogOpen">-->
<!--                        </el-button>-->
<!--                      </el-input>-->
<!--                    </el-form-item>-->
<!--                  </el-col>-->
                  <el-col :md="8" >
                    <el-form-item label="开票日期">
                      <el-date-picker
                        v-model="daterangeInvoiceDate"
                        style="width: 100%"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :md="6" align="right" style="float: right;" >
                    <el-form-item>
                      <el-button class="filter-item" type="primary" @click="handleQuery">搜索</el-button>
                      <el-button class="filter-item" style="margin-left: 8px" @click="resetQuery">重置</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="16">
                  <el-col :md="24" >
                    <el-form-item label="发票类型" prop="invoiceType">
                      <el-row :gutter="16">
                        <el-col :md="2" >
                          <el-checkbox v-model="checkAllInvoiceType" :indeterminate="isInvoiceTypeIndeterminate" label="全选" size="mini" @change="checkAll($event,'invoiceType')" border></el-checkbox>
                        </el-col>
                        <el-col :md="19" >
                          <el-checkbox-group v-model="queryParams.invoiceTypes" @change="handleCheckedChange($event,'invoiceType')">
                            <el-checkbox v-for="dict in dict.type.in_invoice_type" :label="dict.value" :key="dict.value">{{dict.label}}</el-checkbox>
                          </el-checkbox-group>
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </el-col>
                  <el-col :md="24" >
                    <el-form-item label="发票状态" prop="invoiceState">
                      <el-row :gutter="16">
                        <el-col :md="2" >
                          <el-checkbox v-model="checkAllinvoiceState" :indeterminate="isinvoiceStateIndeterminate" label="全选" size="mini" @change="checkAll($event,'invoiceState')" border></el-checkbox>
                        </el-col>
                        <el-col :md="18" >
                          <el-checkbox-group v-model="queryParams.invoiceStatees" @change="handleCheckedChange($event,'invoiceState')">
                            <el-checkbox v-for="dict in dict.type.invoice_status" :label="dict.value" :key="dict.value">{{dict.label}}</el-checkbox>
                          </el-checkbox-group>
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="16">
                  <el-col :md="12" >
                    <el-form-item label="是否认证" prop="deductible">
                      <el-row :gutter="16">
                        <el-col :md="4" >
                          <el-checkbox v-model="checkAlldeductible" :indeterminate="isdeductibleIndeterminate" label="全选" size="mini" @change="checkAll($event,'deductible')" border></el-checkbox>
                        </el-col>
                        <el-col :md="18" >
                          <el-checkbox-group v-model="queryParams.deductibles" @change="handleCheckedChange($event,'deductible')">
                            <el-checkbox v-for="dict in dict.type.deductible" :label="dict.value" :key="dict.value">{{dict.label}}</el-checkbox>
                          </el-checkbox-group>
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="16">
                  <el-col :md="24" >
                    <el-form-item label="认证类型" prop="certificationType">
                      <el-row :gutter="16">
                        <el-col :md="2" >
                          <el-checkbox v-model="checkAllCertificationType" :indeterminate="isCertificationTypeIndeterminate" label="全选" size="mini" @change="checkAll($event,'certificationType')" border></el-checkbox>
                        </el-col>
                        <el-col :md="18" >
                          <el-checkbox-group v-model="queryParams.certificationTypes" @change="handleCheckedChange($event,'certificationType')">
                            <el-checkbox v-for="dict in dict.type.certification_type" :label="dict.value" :key="dict.value">{{dict.label}}</el-checkbox>
                          </el-checkbox-group>
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-card>
            </div>
          </el-form>
        </div>
      </div>
    </el-card>
    <el-card shadow="never" >
      <template #header>
        <el-row>
          <el-col :span="16">
            <div class="card-header">
              <el-button disabled type="text">当前税款所属期：<a style="color: red" title="点击查看统计表" @click="jumpToStat(deductiblePeriod)">{{deductiblePeriod}}</a></el-button>
              <el-button disabled type="text">统计表状态：<span style="color: red">{{statStatusName}}</span></el-button>
              <el-button disabled type="text">本次勾选：<span style="color: red">{{count}}</span> 份</el-button>
              <el-button disabled type="text">金额合计：<span style="color: red">{{totalAmount}}</span> 元</el-button>
              <el-button disabled type="text">税额合计：<span style="color: red">{{totalTax}}</span> 元</el-button>
              <el-button disabled type="text">可抵扣税额合计：<span style="color: red">{{deductTax}}</span> 元</el-button>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="btn_box" align="right" style="float: right;">
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                icon="el-icon-download"
                @click="handleExport"
                size="mini"
                v-hasPermi="['doc:invoice:export']"
              >导出</el-button>
              <right-toolbar :showSearch.sync="showSearch" :columns.sync="columns" :columnsKey.sync="columnsKey" @showSearchFun="showSearchFun" @queryTable="getList" :tableKey.sync="tableKey"></right-toolbar>
            </div>
          </el-col>
        </el-row>
      </template>

      <el-table
        border
        stripe
        default-expand-all
        ref="tableRef"
        :key="tableKey"
        v-loading="loading"
        :data="invoiceList"
        @selection-change="handleSelectionChange"
        :row-style="rowClass"
        :header-cell-style= "{
                'font-size': '14px !important',
                'font-weight': '500 !important',
                'color': 'rgb(0 0 0)',
                'background-color': 'rgb(205 224 255)',
              }"
        highlight-current-row style="width: 100%;"
        :height="tableHeight"
      >
        <el-table-column type="selection" width="55" align="left" />
        <el-table-column label="序号" type="index" align="left" width="55">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <template v-for="item in columns">
<!--          <el-table-column label="公司" align="left" key="siteName" prop="siteName" v-if="item.visible && item.label=='公司'" :show-overflow-tooltip="true" width="200"/>-->
          <el-table-column label="发票类型" align="left" key="invoiceTypeName" prop="invoiceTypeName" v-if="item.visible && item.label=='发票类型'"  width="200"/>
          <el-table-column label="开票日期" align="left" key="invoiceDate" prop="invoiceDate" v-if="item.visible && item.label=='开票日期'"  width="100">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.invoiceDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="发票代码" align="left" key="invoiceCode" prop="invoiceCode" v-if="item.visible && item.label=='发票代码'"  width="120" />
          <el-table-column label="发票号码" align="left" key="invoiceNo" prop="invoiceNo"  v-if="item.visible && item.label=='发票号码'"  width="200"/>
          <el-table-column label="合规结果" align="left" key="isComplianceCollectName" prop="isComplianceCollectName"  v-if="item.visible && item.label=='合规结果'"  width="110"/>
          <el-table-column label="不合规原因" align="left" key="complianceCollectDesc" prop="complianceCollectDesc"  v-if="item.visible && item.label=='不合规原因'"  width="150"/>
          <el-table-column label="购方名称" align="left" key="purchaserName" prop="purchaserName"  v-if="item.visible && item.label=='购方名称'"  width="180"/>
          <el-table-column label="购方税号" align="left" key="purchaserTaxNo" prop="purchaserTaxNo"  v-if="item.visible && item.label=='购方税号'"  width="180"/>
          <el-table-column label="销方名称" align="left" key="saleName" prop="saleName"  v-if="item.visible && item.label=='销方名称'"  width="250" show-overflow-tooltip/>
          <el-table-column label="销方税号" align="left" key="saleTaxNo" prop="saleTaxNo"  v-if="item.visible && item.label=='销方税号'"  width="200"/>
          <el-table-column label="用途备注" align="left" key="useRemark" prop="useRemark"  v-if="item.visible && item.label=='用途备注'"  width="150"/>
          <el-table-column label="不含税金额" align="left" key="totalAmount" prop="totalAmount"  v-if="item.visible && item.label=='不含税金额'"  width="150"/>
          <el-table-column label="合计税额" align="left" key="totalTax" prop="totalTax"  v-if="item.visible && item.label=='合计税额'"  width="150"/>
          <el-table-column label="价税合计" align="left" key="amountTax" prop="amountTax"  v-if="item.visible && item.label=='价税合计'"  width="150"/>
          <el-table-column label="可抵扣税额" align="left" key="deductTax" prop="deductTax"  v-if="item.visible && item.label=='可抵扣税额'"  width="150"/>
          <el-table-column label="开票人" align="left" key="drawer" prop="drawer"  v-if="item.visible && item.label=='开票人'"  width="150"/>
          <el-table-column label="复核人" align="left" key="checker" prop="checker"  v-if="item.visible && item.label=='复核人'"  width="150"/>
          <el-table-column label="收款人" align="left" key="payee" prop="payee"  v-if="item.visible && item.label=='收款人'"  width="150"/>
          <el-table-column label="查验失败描述" align="left" key="inspectionErrorDesc" prop="inspectionErrorDesc"  v-if="item.visible && item.label=='查验失败描述'"  width="150"/>
          <el-table-column label="校验状态" align="left" key="verifyStatusName" prop="verifyStatusName"  v-if="item.visible && item.label=='校验状态'"  width="150"/>
          <el-table-column label="发票状态" align="left" key="invoiceStateName" prop="invoiceStateName"  v-if="item.visible && item.label=='发票状态'"  width="150"/>
          <el-table-column label="红蓝发票" align="left" key="isRedName" prop="isRedName"  v-if="item.visible && item.label=='红蓝发票'"  width="150"/>
          <el-table-column label="税局取票" align="left" key="isPullName" prop="isPullName"  v-if="item.visible && item.label=='税局取票'"  width="150"/>
          <el-table-column label="签收状态" align="left" key="signStatusName" prop="signStatusName"  v-if="item.visible && item.label=='签收状态'"  width="150"/>
          <el-table-column label="推送时间" align="left" key="pushTime" prop="pushTime"  v-if="item.visible && item.label=='推送时间'"  width="150"/>
          <el-table-column label="ERP发票流水号" align="left" key="erpSerialNumber" prop="erpSerialNumber"  v-if="item.visible && item.label=='ERP发票流水号'"  width="150"/>
          <el-table-column label="无法抵扣原因" align="left" key="deductErrorRemark" prop="deductErrorRemark"  v-if="item.visible && item.label=='无法抵扣原因'"  width="150"/>
          <el-table-column label="认证类型" align="left" key="certificationTypeName" prop="certificationTypeName"  v-if="item.visible && item.label=='认证类型'"  width="150"/>
          <el-table-column label="是否认证" align="left" key="deductibleName" prop="deductibleName"  v-if="item.visible && item.label=='抵扣状态'"  width="150"/>
          <el-table-column label="税款所属期" align="left" key="deductiblePeriod" prop="deductiblePeriod"  v-if="item.visible && item.label=='税款所属期'"  width="150"/>
          <el-table-column label="校验码" align="left" key="checkCode" prop="checkCode"  v-if="item.visible && item.label=='校验码'"  width="150"/>
          <el-table-column label="入账状态" align="left" key="accountStatusName" prop="accountStatusName"  v-if="item.visible && item.label=='入账状态'"  width="150"/>
          <el-table-column label="处理状态" align="left" key="processStatusName" prop="processStatusName"  v-if="item.visible && item.label=='处理状态'"  width="150"/>
          <el-table-column label="采集状态" align="left" key="collectStatusName" prop="collectStatusName"  v-if="item.visible && item.label=='采集状态'"  width="150"/>
          <el-table-column label="报销状态" align="left" key="submitStatusName" prop="submitStatusName"  v-if="item.visible && item.label=='报销状态'"  width="150"/>
          <el-table-column label="发票备注" align="left" key="invoiceRemark" prop="invoiceRemark"  v-if="item.visible && item.label=='发票备注'"  width="150"/>
          <el-table-column label="平台来源" align="left" key="platformSource" prop="platformSource"  v-if="item.visible && item.label=='平台来源'"  width="150"/>
          <el-table-column label="备注" align="left" key="remark" prop="remark"  v-if="item.visible && item.label=='平备注台来源'"  width="150"/>
          <el-table-column label="有无影像" align="left" key="hasPictureName" prop="hasPictureName"  v-if="item.visible && item.label=='有无影像'"  width="150"/>
          <el-table-column label="查验时间" align="left" key="inspectionTime" prop="inspectionTime"  v-if="item.visible && item.label=='查验时间'"  width="150">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.inspectionTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="查验状态" align="left" key="inspectionStatusName" prop="inspectionStatusName"  v-if="item.visible && item.label=='查验状态'"  width="150"/>
          <el-table-column label="添加人" align="left" key="createBy" prop="createBy"  v-if="item.visible && item.label=='添加人'"  width="120"/>
          <el-table-column label="修改人" align="left" key="updateBy" prop="updateBy"  v-if="item.visible && item.label=='修改人'"  width="120"/>
          <el-table-column label="修改时间" align="left" key="updateTime" prop="updateTime" v-if="item.visible && item.label=='修改时间'"  width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>

        </template>
        <el-table-column label="操作" align="left" fixed="right" class-name="small-padding fixed-width" width="120">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="jumpToDetail(scope.row)"
              v-hasPermi="['doc:invoice:edit']"
            >查看</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button
              type="text"
              @click="handleOpenInvoice(scope.row.invoiceId)"
              v-hasPermi="['doc:invoice:remove']"
            >附件</el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <svg-icon icon-class="search-none" style="font-size: 64px;" />
          <p>暂无数据</p>
        </div>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 查看发票 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="详情" :visible.sync="invoiceOpen" width="1400px" append-to-body>
        <div class="dialog_box" style="height:660px;">
          <el-row>
            <el-col :span="10">
              <div style="height:635px; overflow-y: auto">
                <el-tabs type="border-card">
                  <el-tab-pane label="发票信息">
                    <el-descriptions class="margin-top" title="基本信息" :column="2" size="small" border>
                      <template slot="title">
                        <div>基本信息 <span class="invoice-type">{{detailForm.invoiceTypeName}}</span></div>
                      </template>
                      <el-descriptions-item>
                        <template slot="label">
                          发票性质:
                        </template>
                        <el-tag type="danger" v-if="detailForm.isRed == 1">红票</el-tag>
                        <el-tag v-else>蓝票</el-tag>
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          发票号码:
                        </template>
                        {{detailForm.invoiceNo}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          开票日期:
                        </template>
                        {{detailForm.invoiceDate}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          金额(不含税):
                        </template>
                        ¥{{detailForm.totalAmount}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          税额:
                        </template>
                        ¥{{detailForm.totalTax}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          金额(含税):
                        </template>
                        ¥{{detailForm.amountTax}}
                      </el-descriptions-item>
                      <el-descriptions-item>
                        <template slot="label">
                          校验码:
                        </template>
                        {{detailForm.checkCode}}
                      </el-descriptions-item>
                    </el-descriptions>
                    <el-descriptions class="margin-top" title="抬头信息" :column="1" size="small" border>
                      <el-descriptions-item>
                        <template slot="label">
                          购方名称:
                        </template>
                        {{detailForm.purchaserName}}
                      </el-descriptions-item>
                      <el-descriptions-item >
                        <template slot="label">
                          购方税号:
                        </template>
                        {{detailForm.purchaserTaxNo}}
                      </el-descriptions-item>
                      <el-descriptions-item >
                        <template slot="label">
                          销方名称:
                        </template>
                        {{detailForm.saleName}}
                      </el-descriptions-item>
                      <el-descriptions-item >
                        <template slot="label">
                          销方税号:
                        </template>
                        {{detailForm.saleTaxNo}}
                      </el-descriptions-item>
                    </el-descriptions>
                    <el-descriptions class="margin-top" title="商品明细" :column="1" size="small" border >
                      <el-descriptions-item>
                        <el-table
                          border
                          stripe
                          default-expand-all
                          ref="invoiceDetailEntry"
                          v-loading="loading"
                          :data="invoiceEntryList"
                          :header-cell-style= "{
                          'font-size': '12px !important',
                          'font-weight': '500 !important',
                          'color':'#FFF',
                          'padding': '0px 0',
                          'background-color':'rgb(51 112 255 / 80%)',
                          textAlign: 'left',
                          'height': '30px !important'
                        }"
                          :cell-style="{ padding: '8px 10px 8px 0', textAlign: 'left' }"
                          highlight-current-row
                          style="width: 555px;margin-left: -32px;margin-top: -10px;"
                          height="300px"
                        >
                          <el-table-column label="序号" align="center" prop="index" width="50">
                            <template slot-scope="scope">{{scope.$index+1}}</template>
                          </el-table-column>
                          <el-table-column label="行号" align="left" prop="rowNo" width="80" show-overflow-tooltip/>
                          <el-table-column label="商品编码" align="left" prop="commodityCode" width="120" show-overflow-tooltip/>
                          <el-table-column label="货物或应税劳务名称" align="left" prop="commodityName" width="160" show-overflow-tooltip/>
                          <el-table-column label="规格型号" align="left" prop="specificationModel" width="140" show-overflow-tooltip/>
                          <el-table-column label="单位" align="left" prop="unit"  show-overflow-tooltip/>
                          <el-table-column label="数量" align="left" prop="quantity"  show-overflow-tooltip/>
                          <el-table-column label="单价" align="left" prop="price" width="100" show-overflow-tooltip>
                            <template slot-scope="scope">
                              ¥{{scope.row.unitPrice}}
                            </template>
                          </el-table-column>
                          <el-table-column label="总额" align="left" prop="amount" width="100"show-overflow-tooltip>
                            <template slot-scope="scope">
                              ¥{{scope.row.amount}}
                            </template>
                          </el-table-column>
                          <el-table-column label="税率" align="left" prop="taxRate"  show-overflow-tooltip>
                            <template slot-scope="scope">
                              {{scope.row.taxRate}}%
                            </template>
                          </el-table-column>
                          <el-table-column label="税额" align="left" prop="tax"  show-overflow-tooltip>
                            <template slot-scope="scope">
                              ¥{{scope.row.tax}}
                            </template>
                          </el-table-column>
                          <div slot="empty">
                            <svg-icon icon-class="search-none" style="font-size: 64px;" />
                            <p>暂无数据</p>
                          </div>
                        </el-table>
                      </el-descriptions-item>

                    </el-descriptions>
                  </el-tab-pane>
                </el-tabs>
              </div>
            </el-col>
            <el-col :span="14">
              <div style="height: 575px; background-color:#404040;padding: 20px;">
                <pdf
                  ref="pdf"
                  key="pdfKey"
                  :rotate="pageRotate"
                  :src="fileUrl"
                  style="width: 100%; height: 500px;"
                ></pdf>
              </div>
              <div style=" margin-top: 20px; text-align: center;">
                <!--                <el-button type="primary" size="mini" title="顺时针旋转" @click="clock" class="mr10"> 顺时针</el-button>-->
                <!--                <el-button type="primary" size="mini" title="逆时针旋转" @click="counterClock" class="mr10"> 逆时针</el-button>-->
                <el-button type="primary" size="mini" @click="scaleD"> 放大</el-button>
                <el-button type="primary" size="mini" @click="scaleX"> 缩小</el-button>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-dialog>

      <!-- 查询条件-公司-弹出查询 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="查询条件-公司查询" :visible.sync="searchsiteCodeDialogOpen" width="800px" append-to-body>
        <div class="dialog_box" style="height:550px;">
          <el-form label-position="left" :model="searchsiteCodeQueryParams" :inline="true"  ref="searchsiteCodeQueryForm" label-width="88px" >
            <el-form-item  prop="searchsiteCodeSearchValue">
              <el-input
                v-model="searchsiteCodeQueryParams.searchValue"
                size="mini"
                placeholder="请输入编码或名称查询公司"
                @keyup.enter.native="handleSearchsiteCodeQuery"
                clearable
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearchsiteCodeQuery">查询</el-button>
            </el-form-item>
          </el-form>
          <el-table v-loading="searchsiteCodeSelectLoading" :data="searchsiteCodeList"
                    height="400"
                    @row-click="handleSearchsiteCodeRowClick"
                    ref="searchsiteCodeMultipleTable"
                    :row-key="getSearchsiteCodeListRowKey"
                    :row-style="{height:2+'px'}"
                    :header-cell-style= "{
                        'font-size': '14px !important',
                        'font-weight': '500 !important',
                        'background-color':'rgb(241 241 241 / 52%)'
                      }"
                    :cell-style="{padding:'2px 4px'}"
                    border
                    @selection-change="handleSearchsiteCodeSelectionChange">
            <el-table-column type="selection" width="55" align="left"/>
            <!-- 数据 -->
            <el-table-column prop="companycode" label="公司代码" width="180"></el-table-column>
            <el-table-column prop="companyname" label="公司名称" ></el-table-column>
            <el-table-column prop="remark" label="备注" width="120"></el-table-column>
          </el-table>
          <pagination
            v-show="searchsiteCodeTotal>0"
            :total="searchsiteCodeTotal"
            :page.sync="searchsiteCodeQueryParams.pageNum"
            :limit.sync="searchsiteCodeQueryParams.pageSize"
            @pagination="getSearchsiteCodeList"
          />
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" type="primary" @click="confirmSearchsiteCode">确 定</el-button>
          <el-button size="mini"   @click="searchsiteCodeCancel">取 消</el-button>
        </div>
      </el-dialog>

      <!-- 不抵扣原因弹出 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="选择不抵扣原因" :visible.sync="reasonOpen" width="600px" append-to-body>
        <div class="dialog_box" style="height:200px;">
          <el-form label-position="left"  :inline="true"  label-width="158px" >
            <el-form-item label="不抵扣原因">
              <el-select v-model="reason" placeholder="请选择不抵扣原因" style="width: 100%;">
                <el-option v-for="dict in dict.type.cancelnon_reason" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="不抵扣原因说明">
              <el-input type="textarea" :rows="2" v-model="reasonRemark" style="width: 360px;"/>
            </el-form-item>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" type="primary" @click="doDeductionCancelnonApply">确 定</el-button>
          <el-button size="mini" @click="cancelDeductionCancelnonApply">取 消</el-button>
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>
<style lang="scss">
  .longBtnBar{

  }
  .longBtnBar .el-form-item--mini .el-form-item__content, .el-form-item--mini .el-form-item__label{
    margin-left: 0px !important;
  }
</style>

<script>
    import { listDeductionInvoice, getInvoice, delInvoice, addInvoice, updateInvoice,
        deductionApply, deductionApplyCancel, deductionCancelnonApply, deductionCancelnonApplyCancel } from "@/api/doc/ininvoice";
    import { listCompany as listcompany, getCompany as getcompany } from "@/api/core/company";
    /* 城市列表 **/
    import { provinceList, cityList, districtList } from "@/api/system/city";
    import pdf from "vue-pdf";
    import { getCurrentDeductionstat } from "@/api/doc/deductionstat";


    export default {
        name: "ApInInvoice",
        components: {
            pdf,
        },
        dicts: ['check_status', 'deductible', 'invoice_status', 'in_invoice_type', 'match_status', 'account_status', 'sign_status', 'submit_status', 'collect_status', 'certification_type', 'cancelnon_reason'],
        data() {
            return {
                advanced: false,
                tableHeight: this.getInitTableHeight(),
                // 遮罩层
                loading: true,
                // 远程查询条件加载
                remoteSearchValueLoading: false,
                // 选中数组
                ids: [],
                // 子表选中数据
                checkedTSalInvoiceEntry: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                tableKey: 5,
                //
                columnsKey: 'apininvoice',
                reasonOpen: false,
                reason: null,
                reasonRemark: null,
                // 自定义列
                columns: [
                    // {
          //     key: 0,
          //     label: `公司`,
          //     visible: true
          // },
                    {
                        key: 1,
                        label: `发票类型`,
                        visible: true
                    }, {
                        key: 2,
                        label: `开票日期`,
                        visible: true
                    }, {
                        key: 3,
                        label: `发票代码`,
                        visible: true
                    }, {
                        key: 4,
                        label: `发票号码`,
                        visible: true
                    }, {
                        key: 5,
                        label: `合规结果`,
                        visible: true
                    }, {
                        key: 6,
                        label: `不合规原因`,
                        visible: true
                    }, {
                        key: 7,
                        label: `购方名称`,
                        visible: true
                    }, {
                        key: 8,
                        label: `购方税号`,
                        visible: true
                    }, {
                        key: 9,
                        label: `销方名称`,
                        visible: true
                    }, {
                        key: 10,
                        label: `销方税号`,
                        visible: true
                    }, {
                        key: 11,
                        label: `用途备注`,
                        visible: true
                    }, {
                        key: 12,
                        label: `不含税金额`,
                        visible: true
                    }, {
                        key: 13,
                        label: `合计税额`,
                        visible: true
                    }, {
                        key: 14,
                        label: `价税合计`,
                        visible: true
                    }, {
                        key: 15,
                        label: `可抵扣税额`,
                        visible: true
                    }, {
                        key: 16,
                        label: `开票人`,
                        visible: true
                    }, {
                        key: 17,
                        label: `复核人`,
                        visible: true
                    }, {
                        key: 18,
                        label: `收款人`,
                        visible: true
                    }, {
                        key: 19,
                        label: `查验失败描述`,
                        visible: true
                    }, {
                        key: 20,
                        label: `校验状态`,
                        visible: true
                    }, {
                        key: 21,
                        label: `发票状态`,
                        visible: true
                    }, {
                        key: 22,
                        label: `红蓝发票`,
                        visible: true
                    }, {
                        key: 23,
                        label: `税局取票`,
                        visible: true
                    }, {
                        key: 24,
                        label: `签收状态`,
                        visible: true
                    }, {
                        key: 25,
                        label: `推送时间`,
                        visible: true
                    }, {
                        key: 26,
                        label: `ERP发票流水号`,
                        visible: true
                    }, {
                        key: 27,
                        label: `无法抵扣原因`,
                        visible: true
                    }, {
                        key: 28,
                        label: `认证类型`,
                        visible: true
                    }, {
                        key: 29,
                        label: `抵扣状态`,
                        visible: true
                    }, {
                        key: 30,
                        label: `税款所属期`,
                        visible: true
                    }, {
                        key: 31,
                        label: `校验码`,
                        visible: true
                    }, {
                        key: 32,
                        label: `入账状态`,
                        visible: true
                    }, {
                        key: 33,
                        label: `处理状态`,
                        visible: true
                    }, {
                        key: 34,
                        label: `采集状态`,
                        visible: true
                    }, {
                        key: 35,
                        label: `报销状态`,
                        visible: true
                    }, {
                        key: 36,
                        label: `发票备注`,
                        visible: true
                    }, {
                        key: 37,
                        label: `平台来源`,
                        visible: true
                    }, {
                        key: 38,
                        label: `备注`,
                        visible: true
                    }, {
                        key: 39,
                        label: `有无影像`,
                        visible: true
                    }, {
                        key: 40,
                        label: `查验时间`,
                        visible: true
                    }, {
                        key: 41,
                        label: `查验状态`,
                        visible: true
                    }, {
                        key: 42,
                        label: `添加人`,
                        visible: true
                    }, {
                        key: 43,
                        label: `修改人`,
                        visible: true
                    }, {
                        key: 44,
                        label: `修改时间`,
                        visible: true
                    }
                ],
                // 总条数
                total: 0,
                // 进项发票表格数据
                invoiceList: [],
                // 进项明细项表格数据
                tSalInvoiceEntryList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 修改时间时间范围
                daterangeInvoiceDate: [],
                // 修改时间时间范围
                daterangeAccountDate: [],
                // 修改时间时间范围
                daterangeCreateTime: [],

                // 关键字查询条件
                searchValueOptions:[

                ],
                deductiblePeriod : null,
                statStatusName : null,
                count : 0,
                totalAmount : 0,
                totalTax : 0,
                deductTax : 0,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    params:{

                    },
                    searchValues: [],
                    siteCode: null,
                    invoiceType: null,
                    invoiceTypes: [],
                    invoiceNo: null,
                    invoiceCode: null,
                    invoiceDate: null,
                    printNumber: null,
                    sellerName: null,
                    sellerNumber: null,
                    buyerNumber: null,
                    buyerTel: null,
                    buyerAccount: null,
                    voucherNumber: null,
                    accountDate: null,
                    deductible: null,
                    deductibles: [],
                    certificationType: null,
                    certificationTypes: [],
                    invoiceState: null,
                    invoiceStatees: [],
                    checkStatus: null,
                    checkStatuses: [],
                    collectStatus: null,
                    collectStatuses: [],
                    signStatus: null,
                    signStatuses: [],
                    matchStatus: null,
                    matchStatuses: [],
                    submitStatus: null,
                    submitStatuses: [],
                    checkCode: null,
                    erpSerialNumber: null,
                    updateBy: null,
                    updateTime: null
                },

                checkAllInvoiceType: false,
                isInvoiceTypeIndeterminate: false,
                checkAllinvoiceState: false,
                isinvoiceStateIndeterminate: false,
                checkAlldeductible: false,
                isdeductibleIndeterminate: false,
                checkAllCheckStatus: false,
                isCheckStatusIndeterminate: false,
                checkAllCollectStatus: false,
                isCollectStatusIndeterminate: false,
                checkAllSignStatus: false,
                isSignStatusIndeterminate: false,
                checkAllMatchStatus: false,
                isMatchStatusIndeterminate: false,
                checkAllSubmitStatus: false,
                isSubmitStatusIndeterminate: false,
                checkAllCertificationType: false,
                isCertificationTypeIndeterminate: false,

                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                invoiceOpen:false,
                detailForm:{},
                invoiceEntryList:[],
                fileUrl:null,
                isBuyer:'销方',
                isWithout:'含税',
                pageRotate: 0,
                scale: 100, //放大系数
                /* ======================================省市区======================================  */
                // 省
                provinceId: null,
                provinceList:[],
                // 市
                cityId: null,
                cityList:[],
                // 区
                districtId: null,
                districtList:[],

                /* ======================================查询条件-公司代码选择======================================  */
                searchsiteCodes:[],
                searchsiteCodenames:[],
                searchsiteCodeTotal: 0,
                searchsiteCodeList: [],
                searchsiteCodeDialogOpen: false,
                searchsiteCodeSelectLoading: false,
                searchsiteCodeQueryParams: {
                    searchValue: null,
                    pageNum: 1,
                    pageSize: 20,
                },
                /* ======================================编辑-公司代码选择======================================  */
                siteCodename: null,
                siteCodeTotal: 0,
                siteCodeList: [],
                siteCodeDialogRadio: null,
                siteCodeDialogOpen: false,
                siteCodeSelectLoading: false,
                siteCodeQueryParams: {
                    searchValue: null,
                    pageNum: 1,
                    pageSize: 20,
                },
            };
        },
        created() {
            this.getList();
            getCurrentDeductionstat().then(response => {
                if(response.data){
                  this.deductiblePeriod = response.data.period;
                  this.statStatusName = response.data.statStatusName;
                }
                this.tInDeductionStatEntryList = response.data.tInDeductionStatEntryList;
                this.open = true;
                this.title = "修改统计表";
            });
        },
        methods: {
            /** 行样式 */
            rowClass({ row, rowIndex }) {
                if (this.ids.includes(row.id)) {
                    return { background: "#d9edf7", height:'20px' };
                } else {
                    return { height:'20px'};
                }
            },
            /** 隐藏搜索按钮操作 */
            showSearchFun(isShowSearch){
                this.showSearch = isShowSearch
                let oldHeight = this.$refs.queryRef.$el.offsetHeight
                if(!isShowSearch){
                    //当前是显示状态
                    oldHeight = oldHeight + 12
                }else{
                    oldHeight = oldHeight - 12
                }
                this.$nextTick(() => (
                    this.tableHeight = this.$refs.tableRef.$el.offsetHeight - (this.$refs.queryRef.$el.offsetHeight-oldHeight)
                ))
            },
            /** 展开按钮操作 */
            toggleAdvanced() {
                const oldHeight = this.$refs.queryRef.$el.offsetHeight
                this.advanced = !this.advanced
                this.$nextTick(() => (
                    this.tableHeight = this.$refs.tableRef.$el.offsetHeight - (this.$refs.queryRef.$el.offsetHeight-oldHeight)
                ))
            },
            /** 查询进项发票列表 */
            getList() {
                this.loading = true;
                this.queryParams.params = {};
                if (null != this.daterangeInvoiceDate && '' != this.daterangeInvoiceDate) {
                    this.queryParams.params["beginInvoiceDate"] = this.daterangeInvoiceDate[0];
                    this.queryParams.params["endInvoiceDate"] = this.daterangeInvoiceDate[1];
                }
                if (null != this.daterangeAccountDate && '' != this.daterangeAccountDate) {
                    this.queryParams.params["beginAccountDate"] = this.daterangeAccountDate[0];
                    this.queryParams.params["endAccountDate"] = this.daterangeAccountDate[1];
                }
                if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
                    this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
                    this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
                }
                listDeductionInvoice(this.queryParams).then(response => {
                    this.invoiceList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: null,
                    invoiceId: null,
                    custId: null,
                    siteCode: null,
                    siteName: null,
                    invoiceType: null,
                    invoiceTypeName: null,
                    invoiceNo: null,
                    invoiceCode: null,
                    invoiceDate: null,
                    printNumber: null,
                    feeWithoutTax: null,
                    fee: null,
                    tax: null,
                    sellerName: null,
                    sellerNumber: null,
                    sellerDest: null,
                    sellerAddress: null,
                    sellerTel: null,
                    sellerBank: null,
                    sellerAccount: null,
                    buyerName: null,
                    buyerNumber: null,
                    buyerAddress: null,
                    buyerTel: null,
                    buyerBank: null,
                    buyerAccount: null,
                    voucherNumber: null,
                    accountDate: null,
                    accountStatus: null,
                    accountStatusName: null,
                    deductible: null,
                    deductibleName: null,
                    invoiceState: null,
                    invoiceStateName: null,
                    checkStatus: null,
                    checkStatusName: null,
                    collectStatus: null,
                    collectStatusName: null,
                    signStatus: null,
                    signStatusName: null,
                    matchStatus: null,
                    matchStatusName: null,
                    submitStatus: null,
                    submitStatusName: null,
                    checkCode: null,
                    invoiceRemark: null,
                    erpSerialNumber: null,
                    createName: null,
                    createTime: null,
                    updateBy: null,
                    updateTime: null
                };
                this.tSalInvoiceEntryList = [];
                this.resetForm("form");
            },


            /* ※※ 查询 省市区 相关方法 start ※※ */
            // 获取省
            getProvinceList(){
                provinceList().then(response => {
                    this.provinceList = response.data;
                });
            },
            // 获取市
            getCityList(){
                console.log(this.provinceId);
                cityList( {"parentId" : this.provinceId } ).then(response => {
                    this.cityList = response.data;
                });
            },
            // 获取区县
            getDistrictList(){
                districtList( {"parentId" : this.cityId } ).then(response => {
                    this.districtList = response.data;
                });
            },
            // 选中省份
            handleChangeProvince(val){
                // 给表单省字段赋值
                this.form.provinceid = val;
                let province = {};
                province = this.provinceList.find((item)=>{
                    return item.id === val;
                });
                this.form.province = province.name;
                // 城市数据清空、区县数据清空;
                this.cityList = [];
                this.districtList = [];
                // 已选市、区数据清空
                this.cityId = null;
                this.districtId = null;
                // 表单城市、区县数据清空
                this.form.cityid = null;
                this.form.city = null;
                this.form.areaid = null;
                this.form.area = null;
                // 获取城市数据
                this.getCityList();
            },
            // 清空省份
            handleClearProvince(){
                // 城市数据清空、区县数据清空;
                this.cityList = [];
                this.districtList = [];
                // 已选市、区数据清空
                this.cityId = null;
                this.districtId = null;
                // 表单城市、区县数据清空
                this.form.cityid = null;
                this.form.city = null;
                this.form.areaid = null;
                this.form.area = null;
            },
            // 选中城市
            handleChangeCity(val){
                // 给表单市字段赋值
                this.form.cityid = val;
                let city = {};
                city = this.cityList.find((item)=>{
                    return item.id === val;
                });
                this.form.city = city.name;
                // 区县数据清空
                this.districtList = [];
                // 已选区县清空
                this.districtId = null;
                // 表单区县清空
                this.form.areaid = null;
                this.form.area = null;
                // 获取城市数据
                this.getDistrictList();
            },
            // 清空省份
            handleClearCity(){
                // 区县数据清空
                this.districtList = [];
                // 已选区县清空
                this.districtId = null;
                // 表单区县清空
                this.form.areaid = null;
                this.form.area = null;
            },
            // 选中区县
            handleChangeDistrict(val){
                // 给表单省字段赋值
                this.form.areaid = val;
                let district = {};
                district = this.districtList.find((item)=>{
                    return item.id === val;
                });
                this.form.area = district.name;
            },
            // 清空省份
            handleClearDistrict(){
                // 表单区县清空
                this.form.areaid = null;
                this.form.area = null;
            },

            /* ※※ 查询 省市区 相关方法 end ※※ */




            /* ※※ 查询 公司代码 相关方法 start ※※ */
            /** ① 弹出查询条件-公司代码 */
            openSearchsiteCodeDialogOpen(){
                this.searchsiteCodeDialogOpen = true;
                // 默认不查询
            },
            /** ② 单击行 **/
            handleSearchsiteCodeRowClick(row, column, event){
                this.$refs.searchsiteCodeSingleTable.toggleRowSelection(row);
            },
            /** ③ 行KEY **/
            getSearchsiteCodeListRowKey(row) {
                return row.companycode
            },
            /** ④ 选中公司代码 **/
            handleSearchsiteCodeSelectionChange(selection) {
                this.searchsiteCodes = selection.map(item => item.siteCode);
                this.searchsiteCodenames = selection.map(item => item.siteName);
            },
            /** ⑤ 点击查询按钮 **/
            handleSearchsiteCodeQuery(){
                this.searchsiteCodeQueryParams.pageNum = 1;
                this.getSearchsiteCodeList();
            },
            /** ⑥ 查询 **/
            getSearchsiteCodeList(){
                this.searchsiteCodeSelectLoading = true;
                listcompany(this.searchsiteCodeQueryParams).then(response => {
                    this.searchsiteCodeList = response.rows;
                    this.searchsiteCodeTotal = response.total;
                    this.searchsiteCodeSelectLoading = false;
                });
            },
            /** ⑦ 点击确认查询 **/
            confirmSearchsiteCode() {
                if(this.searchsiteCodes.length > 0){
                    this.queryParams.params.siteCodes = this.searchsiteCodes.join(',');
                    this.queryParams.params.companynames = this.searchsiteCodenames.join(',');
                }
                // 关闭查询弹出框
                this.searchsiteCodeCancel();
            },
            /** ⑧ 点击关闭查询弹出框 **/
            searchsiteCodeCancel() {
                this.searchsiteCodeDialogOpen = false;
            },
            /* ※※ 查询 公司代码 相关方法 end ※※ */


            /* ※※ 编辑 公司代码 相关方法 start ※※ */
            /** ① 弹出编辑内容-公司代码 */
            opensiteCodeDialogOpen(){
                this.siteCodeDialogOpen = true;
                this.getsiteCodeList();
            },
            /** ② 单击行 **/
            handlesiteCodeRowClick(row, column, event){
                this.$refs.siteCodeSingleTable.toggleRowSelection(row);
            },
            /** ③ 行KEY **/
            getsiteCodeListRowKey(row) {
                return row.companycode
            },
            /** ④ 选中公司代码 **/
            handlesiteCodeSelectionChange(selection) {
                if (selection[0]) {
                    this.siteCodeDialogRadio = selection[0]
                    this.form.companycode = selection[0].companycode;
                    this.form.companyname = selection[0].companyname;
                }
            },
            /** ⑤ 点击查询按钮 **/
            handlesiteCodeQuery(){
                this.siteCodeQueryParams.pageNum = 1;
                this.getsiteCodeList();
            },
            /** ⑥ 查询 **/
            getsiteCodeList(){
                this.siteCodeSelectLoading = true;
                listcompany(this.siteCodeQueryParams).then(response => {
                    this.siteCodeList = response.rows;
                    this.siteCodeTotal = response.total;
                    this.siteCodeSelectLoading = false;
                });
            },
            /** ⑦ 点击确认查询 **/
            confirmsiteCode() {
                this.siteCodeCancel();
            },
            /** ⑧ 点击关闭查询弹出框 **/
            siteCodeCancel() {
                this.siteCodeDialogOpen = false;
            },
            /* ※※ 编辑 公司代码 相关方法 end ※※ */

            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                console.log("this.queryParams:");
                console.log(this.queryParams);
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.daterangeInvoiceDate = [];
                this.daterangeAccountDate = [];
                this.daterangeCreateTime = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id);
                this.single = selection.length!==1
                this.multiple = !selection.length
                // 勾选行统计
                this.count = selection.length;
                selection.map(item => {
                    this.totalAmount = (Number(item.totalAmount ? item.totalAmount : 0) + Number(this.totalAmount)).toFixed(8);
                    this.totalTax = (Number(item.totalTax ? item.totalTax : 0) + Number(this.totalTax)).toFixed(8);
                    this.deductTax = (Number(item.deductTax ? item.deductTax : 0) + Number(this.deductTax)).toFixed(8);
                });
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加进项发票";
            },
            /** 跳转至详情页 */
            jumpToDetail(row){
                const invoiceId = row.invoiceId;
                const invoiceNo = row.invoiceNo;
                // 需要另新增一个标签页
                this.$router.push({path:'/doc/in/detail/' + invoiceId,query:{invoiceId:invoiceId, invoiceNo:invoiceNo, date:new Date().getTime()}})
            },

            /** 跳转统计页 */
            jumpToStat(period){
                alert(period);
                // 需要另新增一个标签页
                // this.$router.push({path:'/doc/in/detail/' + invoiceId,query:{invoiceId:invoiceId, invoiceNo:invoiceNo, date:new Date().getTime()}})
            },

            handleOpenInvoice(id) {
                const invoiceId = id;
                // 查询发票详细
                this.$modal.loading("正在查询，请稍候...");
                getInvoice(invoiceId).then(response => {
                    this.detailForm = response.data;
                    this.invoiceEntryList = response.data.tinInvoiceEntryList;
                    this.fileUrl = this.detailForm.fileAddress;
                    this.$modal.closeLoading();
                    this.invoiceOpen = true;
                });

            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids
                getInvoice(id).then(response => {
                    this.form = response.data;
                    this.tSalInvoiceEntryList = response.data.tSalInvoiceEntryList;
                    this.open = true;
                    this.title = "修改进项发票";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        this.form.tSalInvoiceEntryList = this.tSalInvoiceEntryList;
                        if (this.form.id != null) {
                            updateInvoice(this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.getList();
                            });
                        } else {
                            addInvoice(this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.getList();
                            });
                        }
                    }
                });
            },

            /** 勾选抵扣按钮操作 */
            handleDeductionApply(row) {
                const ids = row.id || this.ids;
                this.$modal.confirm('是否确认勾选抵扣项？').then(function() {
                    return deductionApply(ids);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("操作成功");
                }).catch(() => {});
            },

            /** 勾选抵扣取消按钮操作 */
            handleDeductionApplyCancel(row) {
                const ids = row.id || this.ids;
                this.$modal.confirm('是否确认取消勾选抵扣项？').then(function() {
                    return deductionApplyCancel(ids);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("操作成功");
                }).catch(() => {});
            },

            /** 进项发票勾选不抵扣按钮操作 */
            handleDeductionCancelnonApply(row) {
               this.reasonOpen = true;
            },

            /** 确认进项发票勾选不抵扣按钮操作 */
            doDeductionCancelnonApply() {
                const invoiceIds = this.ids;
                let params = {
                    invoiceIds : invoiceIds,
                    reason : this.reason,
                    reasonRemark : this.reasonRemark,
                }
                this.$modal.confirm('是否确认勾选不抵扣项？').then(function() {
                    return deductionCancelnonApply(params);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("操作成功");
                }).catch(() => {});
            },

            /** 取消进项发票勾选不抵扣按钮操作 */
            cancelDeductionCancelnonApply() {
                this.reason = null;
                this.reasonRemark = null;
                this.reasonOpen = false;
            },


            /** 进项发票取消勾选不抵扣按钮操作 */
            handleDeductionCancelnonApplyCancel(row) {
                this.$modal.confirm('是否确认取消勾选不抵扣项？').then(function() {
                    return deductionCancelnonApplyCancel(invoiceIds);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("操作成功");
                }).catch(() => {});
            },


            /** 进项明细项序号 */
            rowTSalInvoiceEntryIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 进项明细项添加按钮操作 */
            handleAddTSalInvoiceEntry() {
                let obj = {};
                obj.entryId = "";
                obj.custId = "";
                obj.siteCode = "";
                obj.siteName = "";
                obj.itemName = "";
                obj.invoiceCode = "";
                obj.unit = "";
                obj.qty = "";
                obj.withoutPrice = "";
                obj.withoutAmount = "";
                obj.taxRate = "";
                obj.tax = "";
                obj.price = "";
                obj.amount = "";
                obj.createName = "";
                obj.updateBy = "";
                obj.updateTime = "";
                this.tSalInvoiceEntryList.push(obj);
            },
            /** 进项明细项删除按钮操作 */
            handleDeleteTSalInvoiceEntry() {
                if (this.checkedTSalInvoiceEntry.length == 0) {
                    this.$modal.msgError("请先选择要删除的进项明细项数据");
                } else {
                    const tSalInvoiceEntryList = this.tSalInvoiceEntryList;
                    const checkedTSalInvoiceEntry = this.checkedTSalInvoiceEntry;
                    this.tSalInvoiceEntryList = tSalInvoiceEntryList.filter(function(item) {
                        return checkedTSalInvoiceEntry.indexOf(item.index) == -1
                    });
                }
            },
            /** 复选框选中数据 */
            handleTSalInvoiceEntrySelectionChange(selection) {
                this.checkedTSalInvoiceEntry = selection.map(item => item.index)
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download('doc/invoice/export', {
                    ...this.queryParams
                }, `invoice_${new Date().getTime()}.xlsx`)
            },
            /** 动态加载关键字查询条件 */
            remoteSearchValue(query) {
                this.remoteSearchValueLoading = true;
                if (query !== '') {
                    this.searchValueOptions = [
                        {value: '销方名称:' + query ,label: '销方名称:' + query },
                        {value: '发票代码:' + query ,label: '发票代码:' + query },
                        {value: '发票号码:' + query ,label: '发票号码:' + query },
                        {value: '税款所属期:' + query ,label: '税款所属期:' + query },
                    ];
                    this.searchValueOptions.map(item => {
                        this.queryParams.searchValues.map((item2, index) => {
                            if(item.value.startsWith('销方名称') && item2.startsWith('销方名称')){
                                item.disabled = true;
                            }
                            if(item.value.startsWith('发票代码') && item2.startsWith('发票代码')){
                                item.disabled = true;
                            }
                            if(item.value.startsWith('发票号码') && item2.startsWith('发票号码')){
                                item.disabled = true;
                            }
                            if(item.value.startsWith('税款所属期') && item2.startsWith('税款所属期')){
                                item.disabled = true;
                            }
                        })
                    });
                } else {
                    this.searchValueOptions = [];
                }
                this.remoteSearchValueLoading = false;
            },

            checkAll(val, column){
                if(val){
                    switch (column) {
                        case 'invoiceType':
                            this.dict.type.in_invoice_type.map((dict, index) => {
                                this.queryParams.invoiceTypes.push(dict.value)
                            });
                            break;
                        case 'accountStatus':
                            this.dict.type.account_status.map((dict, index) => {
                                this.queryParams.accountStatuses.push(dict.value)
                            });
                            break;
                        case 'deductible':
                            this.dict.type.deductible.map((dict, index) => {
                                this.queryParams.deductibles.push(dict.value)
                            });
                            break;
                        case 'invoiceState':
                            this.dict.type.invoice_status.map((dict, index) => {
                                this.queryParams.invoiceStatees.push(dict.value)
                            });
                            break;
                        case 'checkStatus':
                            this.dict.type.check_status.map((dict, index) => {
                                this.queryParams.checkStatuses.push(dict.value)
                            });
                            break;
                        case 'collectStatus':
                            this.dict.type.collect_status.map((dict, index) => {
                                this.queryParams.collectStatuses.push(dict.value)
                            });
                            break;
                        case 'signStatus':
                            this.dict.type.sign_status.map((dict, index) => {
                                this.queryParams.signStatuses.push(dict.value)
                            });
                            break;
                        case 'matchStatus':
                            this.dict.type.match_status.map((dict, index) => {
                                this.queryParams.matchStatuses.push(dict.value)
                            });
                            break;
                        case 'submitStatus':
                            this.dict.type.submit_status.map((dict, index) => {
                                this.queryParams.submitStatuses.push(dict.value)
                            });
                            break;
                        case 'certificationType':
                            this.dict.type.certification_type.map((dict, index) => {
                                this.queryParams.certificationTypes.push(dict.value)
                            });
                            break;
                    }

                } else {
                    switch (column) {
                        case 'invoiceType':
                            this.queryParams.invoiceTypes = []
                            break;
                        case 'accountStatus':
                            this.queryParams.accountStatuses = []
                            break;
                        case 'deductible':
                            this.queryParams.deductibles = []
                            break;
                        case 'invoiceState':
                            this.queryParams.invoiceStatees = []
                            break;
                        case 'checkStatus':
                            this.queryParams.checkStatuses = []
                            break;
                        case 'collectStatus':
                            this.queryParams.collectStatuses = []
                            break;
                        case 'signStatus':
                            this.queryParams.signStatuses = []
                            break;
                        case 'matchStatus':
                            this.queryParams.matchStatuses = []
                            break;
                        case 'submitStatus':
                            this.queryParams.submitStatuses = []
                            break;
                        case 'certificationType':
                            this.queryParams.certificationTypes = []
                            break;
                    }
                }
                switch (column) {
                    case 'invoiceType':
                        this.isInvoiceTypeIndeterminate = false;
                        break;
                    case 'accountStatus':
                        this.isAccountStatusIndeterminate = false;
                        break;
                    case 'deductible':
                        this.isdeductibleIndeterminate = false;
                        break;
                    case 'invoiceState':
                        this.isinvoiceStateIndeterminate = false;
                        break;
                    case 'checkStatus':
                        this.isCheckStatusIndeterminate = false;
                        break;
                    case 'collectStatus':
                        this.isCollectStatusIndeterminate = false;
                        break;
                    case 'signStatus':
                        this.isSignStatusIndeterminate = false;
                        break;
                    case 'matchStatus':
                        this.isMatchStatusIndeterminate = false;
                        break;
                    case 'submitStatus':
                        this.isSubmitStatusIndeterminate = false;
                        break;
                    case 'certificationType':
                        this.isCertificationTypeIndeterminate = false;
                        break;
                }

            },

            handleCheckedChange(value, column){
                let checkedCount = value.length;
                switch (column) {
                    case 'invoiceType':
                        this.checkAllInvoiceType = checkedCount === this.dict.type.in_invoice_type.length;
                        this.isInvoiceTypeIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.in_invoice_type.length;
                        break;
                    case 'accountStatus':
                        this.checkAllAccountStatus = checkedCount === this.dict.type.account_status.length;
                        this.isAccountStatusIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.account_status.length;
                        break;
                    case 'deductible':
                        this.checkAlldeductible = checkedCount === this.dict.type.deductible.length;
                        this.isdeductibleIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.deductible.length;
                        break;
                    case 'invoiceState':
                        this.checkAllinvoiceState = checkedCount === this.dict.type.invoice_status.length;
                        this.isinvoiceStateIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.invoice_status.length;
                        break;
                    case 'checkStatus':
                        this.checkAllCheckStatus = checkedCount === this.dict.type.check_status.length;
                        this.isCheckStatusIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.check_status.length;
                        break;
                    case 'collectStatus':
                        this.checkAllCollectStatus = checkedCount === this.dict.type.collect_status.length;
                        this.isCollectStatusIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.collect_status.length;
                        break;
                    case 'signStatus':
                        this.checkAllSignStatus = checkedCount === this.dict.type.sign_status.length;
                        this.isSignStatusIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.sign_status.length;
                        break;
                    case 'matchStatus':
                        this.checkAllMatchStatus = checkedCount === this.dict.type.match_status.length;
                        this.isMatchStatusIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.match_status.length;
                        break;
                    case 'submitStatus':
                        this.checkAllSubmitStatus = checkedCount === this.dict.type.submit_status.length;
                        this.isSubmitStatusIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.submit_status.length;
                        break;
                    case 'certificationType':
                        this.checkAllCertificationType = checkedCount === this.dict.type.certification_type.length;
                        this.isCertificationTypeIndeterminate = checkedCount > 0 && checkedCount < this.dict.type.certification_type.length;
                        break;
                }

            },
            //放大
            scaleD() {
                if(this.scale == 100){
                    return;
                }
                this.scale += 5;
                this.$refs.pdf.$el.style.width = parseInt(this.scale) + "%";
            },
            //缩小
            scaleX() {
                if (this.scale < 50) {
                    return;
                }
                this.scale += -5;
                this.$refs.pdf.$el.style.width = parseInt(this.scale) + "%";
            },
        }
    };
</script>
